package com.example.demo;

import com.example.mq.ProgressConsumer;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.swing.*;

/**
 * @author shkstart
 * @create 2023-11-11 20:16
 */
//@Component
public class InitialClass {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @PostConstruct
    public void init() {
        // 在应用程序启动后执行的操作
        System.out.println("Application started. Executing @PostConstruct method...");

        SwingUtilities.invokeLater(() -> {
            new FileChooserUI();
        });


        // 设置 RabbitMQ 消费者，监听队列
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
        container.setConnectionFactory(rabbitTemplate.getConnectionFactory());
        container.setQueueNames("FilePlacingQueue");
        container.setMessageListener(new ProgressConsumer(FileChooserUI.progressBar));
        container.start();

    }
}
